/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.heyma.app.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.Type;

/**
 *
 * @author John
 */
@Entity
@Table(schema = "directory", name = "cuentas")
public class UserEntity implements Serializable {

    @Id
    private Long id;
    private String tipo;
    @Column(unique = true, nullable = false)
    private String usuario;
    @Column(unique = true, nullable = false)
    private Long persona_id;
    @Column(nullable = false)
    private String passwords;
    private boolean active;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date desde;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date hasta;
    @Column(nullable = false)
    private String responsable;
    @Type(type = "text")
    private String descripcion;
    @OneToMany(fetch = FetchType.LAZY)
    private Collection<SecurityRoleEntity> roles;

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public Long getPersona_id() {
        return persona_id;
    }

    public void setPersona_id(Long persona_id) {
        this.persona_id = persona_id;
    }

    public String getPasswords() {
        return passwords;
    }

    public void setPasswords(String passwords) {
        this.passwords = passwords;
    }

    public Date getDesde() {
        return desde;
    }

    public void setDesde(Date desde) {
        this.desde = desde;
    }

    public Date getHasta() {
        return hasta;
    }

    public void setHasta(Date hasta) {
        this.hasta = hasta;
    }

    public boolean isActive() {
        Date now = new Date();
        if (now.getTime() < this.desde.getTime()) {
            return false;
        }
        if (this.hasta != null) {
            if (now.getTime() > this.hasta.getTime()) {
                return false;
            }
        }
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Collection<SecurityRoleEntity> getRoles() {
        return roles;
    }

    public void setRoles(Collection<SecurityRoleEntity> roles) {
        this.roles = roles;
    }

    public String getResponsable() {
        return responsable;
    }

    public void setResponsable(String responsable) {
        this.responsable = responsable;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }
}
